package org.duoyi.striver.service.task;

import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.duoyi.striver.consts.TaskEnum;
import org.duoyi.striver.consts.TaskState;
import org.duoyi.striver.service.Task;
import org.duoyi.striver.service.common.CommonService;

/**
 * 任务接口
 */
@Slf4j
public abstract class AbstractTask implements Task {

    @Getter
    protected String name;

    @Getter
    protected TaskState state;

    public AbstractTask() {
        this.name = TaskEnum.getByClass(this.getClass()).name();
        this.state = TaskState.NOT_START;
    }

    @Override
    public void start() {
        this.state = TaskState.RUNNING;
        CommonService.closeAllPanel();
        log.info("开始任务【{}}】", name);
        doTask();
        log.info("完成任务【{}】", name);
        this.state = TaskState.FINISHED;
    }

    public abstract void doTask();

}
